## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-

import os.path

def configure(conf):
    if conf.env['ENABLE_THREADING']:
        conf.env['ENABLE_TAP'] = conf.check(header_name='linux/if_tun.h',
                                            define_name='HAVE_IF_TUN_H')
        conf.report_optional_feature("TapBridge", "Tap Bridge",
                                     conf.env['ENABLE_TAP'],
                                     "<linux/if_tun.h> include not detected")
    else:
        conf.report_optional_feature("TapBridge", "Tap Bridge",
                                     False,
                                     "needs threading support which is not available")

    if conf.env['ENABLE_TAP']:
        blddir = os.path.abspath(os.path.join(conf.blddir, conf.env.variant()))
        tapcreatordir = os.path.abspath(os.path.join(blddir, "src/devices/tap-bridge"))
        conf.env.append_value('NS3_EXECUTABLE_PATH', tapcreatordir)

def build(bld):
    module = bld.create_ns3_module('tap-bridge', ['node'])
    module.source = [
        ]
    headers = bld.new_task_gen('ns3header')
    headers.module = 'tap-bridge'
    headers.source = [
        'tap.h',
        ]

    env = bld.env_of_name('default')
    if env['ENABLE_TAP']:
        module.source.extend([
                'tap-bridge.cc',
                'tap-encode-decode.cc',
                ])
        headers.source.extend([
                'tap-bridge.h',
                ])


        if not env['PLATFORM'].startswith('freebsd'):
            obj = bld.create_suid_program('tap-creator')
            obj.source = [
                'tap-creator.cc',
                'tap-encode-decode.cc',
                ]


